package com.hujia.hjsurprisemeal.controller;

import com.hujia.hjsurprisemeal.model.Order;
import com.hujia.hjsurprisemeal.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")  // 修改基础路径为 /orders
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/place")
    public ResponseEntity<Order> placeOrder(@RequestParam Integer userId,
                                            @RequestParam List<Integer> dishIds) {
        try {
            Order order = orderService.placeOrder(userId, dishIds);
            return ResponseEntity.ok(order);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(null);
        }
    }
}